package com.hopes.bizz.poll.job;

import com.hopes.bizz.poll.alarm.service.PollAlarmExceptionService;
import com.hopes.bizz.poll.alarm.service.PollAlarmNetService;
import com.hopes.bizz.poll.alarm.service.PollAlarmService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/5/29 9:20
 * @Description:
 */
@Service
@Slf4j
public class AlarmJobService {

    @Autowired
    private PollAlarmService pollAlarmService;

    @Autowired
    private PollAlarmNetService pollAlarmNetService;

    @Autowired
    private PollAlarmExceptionService pollAlarmExceptionService;

    @XxlJob("alarmNetJobHandler")
    public void alarmNetJobHandler() {
        long start = System.currentTimeMillis();
        log.info("----------------断网报警统计中----------------`");
        Boolean result = pollAlarmNetService.alarmNetJobHandler();
        log.info("----------------断网报警统计结束,结果为={},耗时(毫秒)={}----------------`", result, System.currentTimeMillis() - start);
        // 设置任务结果
        XxlJobHelper.handleSuccess();
    }

    @XxlJob("alarmJobHandler")
    public void alarmJobHandler() {
        long start = System.currentTimeMillis();
        log.info("----------------超标报警统计中----------------`");
        Boolean result = pollAlarmService.alarmJobHandler();
        log.info("----------------超标报警统计结束,结果为={},耗时(毫秒)={}----------------`", result, System.currentTimeMillis() - start);
        // 设置任务结果
        XxlJobHelper.handleSuccess();
    }

    @XxlJob("alarmExceptionJobHandler")
    public void alarmExceptionJobHandler() {
        long start = System.currentTimeMillis();
        log.info("----------------异常报警统计中----------------`");
        Boolean result = pollAlarmExceptionService.alarmExceptionJobHandler();
        log.info("----------------异常报警统计结束,结果为={},耗时(毫秒)={}----------------`", result, System.currentTimeMillis() - start);
        // 设置任务结果
        XxlJobHelper.handleSuccess();
    }
}
